fix(gate): anchor current state on the project's main line, not the newest scan - #6
Merged
Conversation
…ewest scan latest_succeeded_scan_id ordered purely by recency, so a project scanned on both main and release/1.x resolved its Overview, badges and — since the build gate resolves through the same function — its CI verdict to whichever branch finished last. main's pipeline could be blocked by a release branch's critical CVE. The anchor now prefers a scan whose ref matches the project's default branch, falling back to main (unset on almost every row) and then to the old project-wide rule, so a project that matches neither is unaffected. gate-result also takes ?ref= for a CI job to name its own branch.
This was referenced Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
latest_succeeded_scan_id— the single resolver behind Overview, the project-list badges, the inventory and the build gate — ordered purely by recency. A project wired to CI on bothmainandrelease/1.xtherefore resolved its current state to whichever branch finished last, and sinceevaluate_gategoes through the same function,main's pipeline could be blocked by a release branch's critical CVE. The write side already knew the branch (Scan.ref, normalized at scan-create); every read path ignored it.The anchor now prefers a scan on the project's main line, ordering by that preference before recency:
projects.default_branchwhen set, elsemain, and if neither matches any scan it falls through to the old project-wide rule. That fallback is what makes it safe — a project ontrunk, or one whose scans are all ref-less ad-hoc runs, behaves exactly as before. Themainguess matters becausedefault_branchis NULL on ~97% of rows here; the create form never asks for it and the source pipeline clones the remote's own HEAD rather than passing--branch.GET .../gate-resultalso takes?ref=so a CI job can name its own branch instead of relying on the guess. It is exact: a branch with no succeeded scan returns the no-signal pass rather than borrowing another branch's findings. That required threading the ref intoevaluate_gateas well — the router's resolvedNonemeans both "not pinned" and "that branch has nothing", and only the ref distinguishes them.Eight integration failures and three unit failures showed up locally; all eleven reproduce unchanged on
main(accumulated rows in my dev database, plus a disk-guard trip at 96.8% full), so none are from this change.